// JavaScript Document


//为字符串增加trim方法，使用正则表达式截取空格
String.prototype.trim = function(){							
	return this.replace(/^\s*/,"").replace(/\s*$/,"");
}

var get = function(id){                           
	return document.getElementById(id);            
}

//接案员验证
function managerCheck(){
	var manager = get("manager");				
	var exreg = /(^[A-Za-z0-9]{6,16}$)|(^[\u4E00-\u9FA5]{2,8}$)/;
	if(manager.value == null || manager.value.trim() == ""){
		manager.style.border = "1px solid";
		manager.style.borderColor = "red";
		get("managermsg").innerHTML = '<font color="red" size="2px">请输入接案员名字</font>';
		return false;					
	}else if(!exreg.test(manager.value)){
		manager.style.border = "1px solid";
		manager.style.borderColor = "red";
		get("managermsg").innerHTML = '<font color="red" size="2px">6-16个字符或2-8个中文</font>';			
		return false;
	}else{
		manager.style.border = "";
		get("managermsg").innerHTML = '<font color="green" size="2px">√</font>';
		return true;
	}
}

//原密码验证
function oldPwdCheck(){
	var oldPwd = get("oldpwd");						//密码
	if(oldPwd.value == null || oldPwd.value.trim() == ""){	
		oldPwd.style.border = "1px solid";
		oldPwd.style.borderColor = "red";	
		get("oldpwdmsg").innerHTML = '<font color="red" size="2px">请输入原密码</font>';	
		return false;
	}else{
		oldPwd.style.border = "";
		get("oldpwdmsg").innerHTML = '<font color="green" size="2px">√</font>';
		return true;
	}
}

//调用原密码验证
get("oldpwd").onblur = function(){
	oldPwdCheck();
	
	if(get("oldpwd").value != ""){
		oldpwd();
	}
}

//密码验证
function pwdCheck(){
	var pwd = get("pwd");								//密码
	var exreg = /^[\x21-\x7E]{6,20}$/;					//正则表达式
	if(pwd.value == null || pwd.value.trim() == ""){	
		pwd.style.border = "1px solid";
		pwd.style.borderColor = "red";		
		get("pwdmsg").innerHTML = '<font color="red" size="2px">请输入密码</font>';	
		return false;
	}else if(!exreg.test(pwd.value)){
		pwd.style.border = "1px solid";
		pwd.style.borderColor = "red";		
		get("pwdmsg").innerHTML = '<font color="red" size="2px">6-20个字符，建议由数字和符合两种以上组合</font>';	
		return false;
	}else{
		pwd.style.border = "";
		get("pwdmsg").innerHTML = '<font color="green" size="2px">√</font>';
		return true;
	}
}

//再次确认密码
function rPwdCheck(){     
	var pwd2 = get("rpwd");
	var pwd = get("pwd");	
	if(pwd2.value == null || pwd2.value.trim() == ""){
		pwd2.style.border = "1px solid";
		pwd2.style.borderColor = "red";	
		get("rpwdmsg").innerHTML = '<font color="red" size="2px">请再次输入密码</font>';
		return false;
	}else if(pwd.value != pwd2.value || pwd2.value == ""){
		pwd2.style.border = "1px solid";
		pwd2.style.borderColor = "red";	
		get("rpwdmsg").innerHTML = '<font color="red" size="2px">您输入的两次密码不一致，请再次确认</font>';
		return false;
	}else{
		pwd2.style.border = "";	
		get("rpwdmsg").innerHTML = '<font color="green" size="2px">√</font>';
		return true;
	}
}

//手机验证
function cphoneCheck(){
	var smphone = get("smphone");
	var phoneRegex = /^[1][358][0-9]{9}$/;	//正则表达式
	
	if(smphone.value == "" || smphone.value == null){
		smphone.style.border = "1px solid";
		smphone.style.borderColor = "red";
		get("smphonemsg").innerHTML = "<font color='red' size='1px'>请填写手机号码！</font>";
		return false;
	}else if(!phoneRegex.test(smphone.value)){
		smphone.style.border = "1px solid";
		smphone.style.borderColor = "red";
		get("smphonemsg").innerHTML = "<font color='red' size='1px'>您填写的手机号码格式不对！请核对后重新填写~</font>";
		return false;
	}else{
		smphone.style.border = "";
		get("smphonemsg").innerHTML = '<font color="green" size="2px">√</font>'
		return true;
	}
}

//部门验证
function sdnameCheck(){
	var sdname = get("sdname");				

	if(sdname.value == "--部门--"){	
		sdname.style.border = "1px solid";
		sdname.style.borderColor = "red";
		get("sdnamemsg").innerHTML = '<font color="red" size="2px">请选择部门</font>';
		return false;					
	}else{
		sdname.style.border = "";
		get("sdnamemsg").innerHTML = '<font color="green" size="2px">√</font>';
		return true;
	}
}

//角色验证
function sysroleCheck(){
	var count = 0;
	var sysroleArr = document.getElementsByName("sysrole");
	
	for(var i=0; i<sysroleArr.length; i++){
		if(sysroleArr[i].checked == true){
			count++;
		}	
	}	
	
	if(count == 0){
		get("sysrolemsg").innerHTML = '<font color="red" size="2px">请至少选择一项</font>';
		return false;
	}else{
		get("sysrolemsg").innerHTML = "";
		return true;
	}
}



function checkAll(){
	return managerCheck() && pwdCheck() && rPwdCheck() && cphoneCheck() && sdnameCheck() && sysroleCheck();
}

function checkAll2(){
	return managerCheck() || pwdCheck() || rPwdCheck() || cphoneCheck() || sdnameCheck() || sysroleCheck();
}

function checkPwdAll(){
	return oldPwdCheck() && pwdCheck() && rPwdCheck();// && oldpwd() ;
}